<?php

if(!empty($irtsave) and $irtsave=='yes')
{
set_subtitle_increase_replay_time($subtitle_id, $irtseconds);
}

$increase_replay_time = get_subtitle_increase_replay_time($subtitle_id);
$ipt_option = "";
for ($i = 0; $i <= 10; $i++) {
if($i==$increase_replay_time){$selected="selected='selected'";}else{$selected="";}
    $ipt_option = $ipt_option . "<option value='".$i."' ".$selected.">".$i."</option>";
}

//print_r(get_subtitle_lines_numbers($subtitle_id));
$subtitle_lines_numbers = get_subtitle_lines_numbers($subtitle_id);
$st_subtitle_lines_numbers = "";
for ($i = 0; $i <= count($subtitle_lines_numbers)-1; $i++) {
    $st_subtitle_lines_numbers = $st_subtitle_lines_numbers . "<option value='".$subtitle_lines_numbers[$i]['line_number']."'>".$subtitle_lines_numbers[$i]['line_number']."</option>";
}

$st_time_seconds = '';
for ($i = 1; $i <= 300; $i++) {
    $st_time_seconds = $st_time_seconds . "<option value='".$i."'>".$i."</option>";
}

//
//echo convert_seconds_to_srt_time(convert_srt_time_to_seconds_full($start));

if(!empty($itssave))
{
//echo $itsfrom;
//echo $itsto;
//echo $itsseconds;
$its_subtitle_info = get_subtitle_info($subtitle_id);
$its_table_name = $its_subtitle_info['table_name'];
//echo $its_table_name;
$res = mysql_query("SELECT * FROM `$its_table_name` WHERE `line_number` BETWEEN '$itsfrom' AND '$itsto'");
while ($row = mysql_fetch_array($res)) 
	{
     $id = $row['id'];
	 $start = $row['start'];
	 $end = $row['end'];
	 $new_start = convert_srt_time_to_seconds_full($start);
	 $new_start = $new_start + $itsseconds;
	 $new_start = convert_seconds_to_srt_time($new_start);
	 $new_end = convert_srt_time_to_seconds_full($end);
	 $new_end = $new_end + $itsseconds;
	 $new_end = convert_seconds_to_srt_time($new_end);	 
	 mysql_query("UPDATE `$its_table_name` SET `start` = '$new_start' WHERE `id` = '$id';");
	 mysql_query("UPDATE `$its_table_name` SET `end` = '$new_end' WHERE `id` = '$id';");
	}
	arrange_subtitle_lines_order($its_table_name);
}

if(!empty($dtssave))
{
//echo $dtsfrom;
//echo $dtsto;
//echo $dtsseconds;
$dts_subtitle_info = get_subtitle_info($subtitle_id);
$dts_table_name = $dts_subtitle_info['table_name'];
//echo $its_table_name;
$res = mysql_query("SELECT * FROM `$dts_table_name` WHERE `line_number` BETWEEN '$dtsfrom' AND '$dtsto'");
while ($row = mysql_fetch_array($res)) 
	{
     $id = $row['id'];
	 $start = $row['start'];
	 $end = $row['end'];
	 $new_start = convert_srt_time_to_seconds_full($start);
	 $new_start = $new_start - $dtsseconds;
	 $new_start = convert_seconds_to_srt_time($new_start);
	 $new_end = convert_srt_time_to_seconds_full($end);
	 $new_end = $new_end - $dtsseconds;
	 $new_end = convert_seconds_to_srt_time($new_end);	 
	 mysql_query("UPDATE `$dts_table_name` SET `start` = '$new_start' WHERE `id` = '$id';");
	 mysql_query("UPDATE `$dts_table_name` SET `end` = '$new_end' WHERE `id` = '$id';");
	}
	arrange_subtitle_lines_order($dts_table_name);
}
/////////////////////////////////////////////

$subtitle_tools = "
<style>
div.st-controler{
float:left;
margin:2px;
}
input.image.st-imgcontroler{
width:24px;
height:24px;
}
</style>

<script>
function hidedivs(){
$('#irt').hide();
$('#its').hide();
$('#dts').hide();
}

$(document).ready(function() {
  hidedivs();
});
</script>


<div class='st-controler'><input type='image' class='st-imgcontroler' src='templates/".read_option('theme_folder')."/control/Left-right.png' title='Increase Replay Time' OnClick=hidedivs();$('#irt').show();></div>
<div class='st-controler'><input type='image' class='st-imgcontroler' src='templates/".read_option('theme_folder')."/control/Increase_time.png' title='Increase Time Shift' OnClick=hidedivs();$('#its').show();></div>
<div class='st-controler'><input type='image' class='st-imgcontroler' src='templates/".read_option('theme_folder')."/control/Decrease_time.png' title='Decrease Time Shift' OnClick=hidedivs();$('#dts').show();></div>




<div style='clear:left;'></div>


<div id='irt'>
<form method='post' action='index.php'>
increase replay time: 
<select name='irtseconds' onchange='this.form.submit();'>
".$ipt_option."
</select>
 seconds
<input type='hidden' name='subtitle_id' value='".$subtitle_id."'/>
<input type='hidden' name='page' value='subtitle'/>
<input type='hidden' name='action' value='open'/>
<input type='hidden' name='irtsave' value='yes'/>
</form>
</div>


<div id='its'>
<form method='post' action='index.php'>
increase time shift: 
from line <select name='itsfrom'>".$st_subtitle_lines_numbers."</select>
to line <select name='itsto'>".$st_subtitle_lines_numbers."</select>
increase <select name='itsseconds'>".$st_time_seconds."</select> seconds
<input type='submit' value='save' />
<input type='hidden' name='subtitle_id' value='".$subtitle_id."'/>
<input type='hidden' name='page' value='subtitle'/>
<input type='hidden' name='action' value='open'/>
<input type='hidden' name='itssave' value='yes'/>
</form>
</div>


<div id='dts'>
<form method='post' action='index.php'>
Decrease time shift: 
from line <select name='dtsfrom'>".$st_subtitle_lines_numbers."</select>
to line <select name='dtsto'>".$st_subtitle_lines_numbers."</select>
decrease <select name='dtsseconds'>".$st_time_seconds."</select> seconds
<input type='submit' value='save' />
<input type='hidden' name='subtitle_id' value='".$subtitle_id."'/>
<input type='hidden' name='page' value='subtitle'/>
<input type='hidden' name='action' value='open'/>
<input type='hidden' name='dtssave' value='yes'/>
</form>
</div>

";

?>